
#ifndef PROFILE_H
#define PROFILE_H

#include <chrono>
#include <iostream>
struct TimeProfile
{
    std::chrono::high_resolution_clock::time_point start_time;
    std::chrono::high_resolution_clock::time_point stop_time;
    std::time_t time;

    enum timeUnit
    {
        s,
        ms,
        us,
        ns
    };

    void tic()
    {
        start_time = std::chrono::high_resolution_clock::now();
    }

    std::time_t toc()
    {
        stop_time = std::chrono::high_resolution_clock::now();
        this->time = std::chrono::duration_cast<std::chrono::milliseconds>(stop_time-this->start_time).count();
        printf("Duration time: %ld [ms]\n", time);
        return this->time;
    }

    std::time_t toc(timeUnit unit)
    {
        stop_time = std::chrono::high_resolution_clock::now();
        switch (static_cast<int>(unit)) {
        case 0:
            this->time = std::chrono::duration_cast<std::chrono::seconds>(stop_time-this->start_time).count();
            printf("Duration time: %ld [s]\n", this->time);
            break;
        case 1:
            this->time = std::chrono::duration_cast<std::chrono::milliseconds>(stop_time-this->start_time).count();
            printf("Duration time: %ld [ms]\n", this->time);
            break;
        case 2:
            this->time = std::chrono::duration_cast<std::chrono::microseconds>(stop_time-this->start_time).count();
            printf("Duration time: %ld [us]\n", this->time);
            break;
        case 3:
            this->time = std::chrono::duration_cast<std::chrono::nanoseconds>(stop_time-this->start_time).count();
            printf("Duration time: %ld [ns]\n", this->time);
            break;
        default:
            this->time = std::chrono::duration_cast<std::chrono::milliseconds>(stop_time-this->start_time).count();
            printf("Duration time: %ld [ms]\n", this->time);
            break;
        }
        return this->time;
    }
};

#endif // PROFILE_H
